package main

import (
	"os"
	"net/http"
	"git.oschina.net/YPTArch/processcache/sys/logs"
	"git.oschina.net/YPTArch/processcache/sys/router"
	"git.oschina.net/YPTArch/processcache/sys/redis"
	"git.oschina.net/YPTArch/processcache/conf"
	"strconv"
)

func init()  {
	////配置
	//config.Conf = new(config.Config)
	//if err := config.LoadConfig(); err != nil {
	//	os.Exit(1)
	//}
	//设置日志级别
	level, err := strconv.Atoi(conf.GetLogLevel())
	if err != nil {
		logs.Logger.Error("set log level error:"+err.Error())
		os.Exit(1)
	}
	logs.SetLevel(level)
	//redis
	dbIndex, err := strconv.Atoi(conf.GetDbIndex())
	if err != nil {
		logs.Logger.Error(err.Error())
		os.Exit(1)
	}

	maxIdle, err := strconv.Atoi(conf.GetMaxIdle())
	if err != nil {
		logs.Logger.Error(err.Error())
		os.Exit(1)
	}

	maxActive, err := strconv.Atoi(conf.GetMaxActive())
	if err != nil {
		logs.Logger.Error(err.Error())
		os.Exit(1)
	}
	idleTimeout, err := strconv.Atoi(conf.GetIdleTimeout())
	if err != nil {
		logs.Logger.Error(err.Error())
		os.Exit(1)
	}

	redis.SetPool(conf.GetRedisNetType(), conf.GetRedisAddr(), conf.GetRedisPassword(), dbIndex, maxIdle, maxActive, idleTimeout)
}

func main() {
	router.InitRouter()
	err := http.ListenAndServe(conf.GetServerBind(), nil) //设置监听的端口
	if err != nil {
		logs.Logger.Panic("ListenAndServe: " + err.Error())
		os.Exit(1)
	}
}

